package cn.yuxiaoyuan.template;

import cn.yuxiaoyuan.domain.OpenIdResult;
import cn.yuxiaoyuan.properties.WechatProperties;

import java.util.UUID;

/**
 * @author solargen
 * @version 1.0
 * @date 2025/6/16 10:29
 */
public class WechatLoginTemplate {
    private WechatProperties wechatProperties;

    /**
     * 构造方法
     * @param wechatProperties 微信配置
     */
    public WechatLoginTemplate(WechatProperties wechatProperties) {
        this.wechatProperties = wechatProperties;
    }

    public OpenIdResult getWechatAccessTokenUrl(String code) {
        String format = String.format(wechatProperties.getOpenidurl(), wechatProperties.getAppid(), wechatProperties.getAppsecret(), code);
        System.out.println("发送请求到："+format);
//        String s = HttpUtil.get(format);
//        OpenIdResult openIdResult = JSON.parseObject(s, OpenIdResult.class);
        OpenIdResult openIdResult = new OpenIdResult();
        String openid = UUID.randomUUID().toString();
        System.out.println("openid:"+openid);
        openIdResult.setOpenid(openid);
        String sessionKey = UUID.randomUUID().toString();
        System.out.println("sessionKey："+sessionKey);
        openIdResult.setSession_key(sessionKey);
        return openIdResult;
    }


}
